// pages/order/list.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        order:"",
        pages:0,
        last_page:0,
        status:1
    },

    payment(e){
        console.log(e);
        let oid = e.currentTarget.dataset.oid;
        let _this = this;
        let token = wx.getStorageSync('token');
        wx.request({
          url: 'http://www.order.com/order/Admin/orderPayment',
          data:{token,oid},
          success:function(res){
              console.log(res);
              if(res.data.code==0){
                  wx.showToast({
                    title: '支付成功',
                  })
              }
          },
          fail:function(){
              wx.showToast({
                title: '网络异常请重试',
              })
          }
        })
        
        
    },

    changeTabs(e){
        let status = e.detail.activeKey;
        this.setData({
            status:status
        })
        let _this = this;
        let token = wx.getStorageSync('token');
        wx.request({
            url: 'http://www.order.com/order/Admin/orderList',
            data:{token,status},
            success:function(res){
                _this.setData({
                    order:res.data.data.data,
                    pages:res.data.data.current_page,
                    last_page:res.data.data.last_page,
                })
            }
  
          })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let _this = this;
        let token = wx.getStorageSync('token');
        let status = 0;
        wx.request({
          url: 'http://www.order.com/order/Admin/orderList',
          data:{token,status},
          success:function(res){
              console.log(res);
              _this.setData({
                  order:res.data.data.data,
                  pages:res.data.data.current_page,
                  last_page:res.data.data.last_page,
              })
          }

        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        let spage = this.data.pages+1;
        if(spage>this.data.last_page){
            wx.showToast({
              title: '数据加载完毕',
            })
            return false;
        }
        let _this = this;
        let token = wx.getStorageSync('token');
        let status = this.data.status;
        wx.request({
            url: 'http://www.order.com/order/Admin/orderList',
            data:{token,status},
            success:function(res){
                let arr = res.data.data.data;
                arr.forEach(function(v,k){
                    _this.data.order.push(v);
                });
                _this.setData({
                    order:_this.data.order,
                    pages:spage,
                    last_page:res.data.data.last_page
                })
            }
  
          })

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})